"""
捕获异常
"""
try:
    file_a = open("/Users/caozitong/Desktop/pytest1.txt", "r", encoding="utf-8")
except:
    print("111")

# 捕获多个指定异常，只会捕获指定的异常
try:
    # print(name)
    1 / 0
except (NameError, ZeroDivisionError) as a:
    print(a)


# 捕获所有异常
try:
    print("zhangsan")
except Exception as e:
    print(e)

# 捕获异常-else，如果没有出现异常，会执行else中的代码
try:
    print("zhangsan")
except Exception as e:
    print(e)
else:
    print("2222")

# 捕获异常-finally，不管有没有出现异常，都会执行finally中的代码
try:
    print("zhangsan")
except Exception as e:
    print(e)
finally:
    print("2222")




